package com.huanwei.mini.http;

import android.content.Context;
import android.util.Log;

import com.huanwei.mini.utils.JSONUtils;
import com.huanwei.mini.utils.Okhttp;
import com.huanwei.mini.utils.SpfUtils;

import java.io.File;
import java.util.HashMap;
import java.util.Map;


/**
 * Created by 智江鹏 on 2016/11/18.
 *  API封装
 */

public class API {



    //列表
    public static final String BASE = "https://www.txcgcl.com/mobileapi/login.php?act=login_as";
    public static final String SY = "https://www.txcgcl.com/mobileapi/webAs/index.php";
    //第三個
    public static final String Mulu = "https://www.txcgcl.com/mobileapi/webAs/menu.json.php";
    public static final String CC = "https://www.txcgcl.com/mobileapi/webas/newmsg_count.php?act=getmsg_count";
    //
    public static final String GeRen = "https://www.txcgcl.com/mobileapi/webas/userinfo_json.php?act=getuserinfo";
    public static final String Saveuserinfo = "https://www.txcgcl.com/mobileapi/webas/userinfo_json.php?act=saveuserinfo";
    public static final String Getlist = "https://www.txcgcl.com/mobileapi/webas/daliy.php?act=getlist";

    public static final String Getuser = "https://www.txcgcl.com/mobileapi/webas/daily.php?act=getuser";

    public static final String getsp = "https://www.txcgcl.com/mobileapi/webas/daliy.php?act=add";

//    https://www.txcgcl.com/mobileapi/webas/userinfo_json.php?act=acountlist 获取全部岗位信息（切换身份处点击展开下拉框显示全部岗位）

//    https://www.txcgcl.com/mobileapi/webas/userinfo_json.php?act=changeacount 切换岗位（从acountlist所选择的岗位中获取到的userid和id返回给我）
    public static void login(String username,
                             String pwd, Okhttp.Objectcallback callback) {
        Map<String, String> map = new HashMap<>();

        map.put("username", username);
        map.put("pwd", pwd);

        Okhttp.get(BASE  , map, callback);

    }

    public static void zhuce(String phonenumber, String mbnumber,
                             String username, String pwd, String mbname, Okhttp.Objectcallback callback) {
        Map<String, String> map = new HashMap<>();
        //电话号码
        map.put("phonenumber", phonenumber);
        //身份证号
        map.put("mbnumber", mbnumber);
        map.put("username", username);
        map.put("pwd", pwd);
        map.put("mbname", mbname);


        Okhttp.get(BASE + "register_as", map, callback);

    }

    public static void gz(Context context
            , Okhttp.Objectcallback callback) {

        String sessionkey = (String) SpfUtils.get(context, "sessionkey", "");
        Log.e("xxxx", "URL" + API.Mulu + "&sessionkey=" + sessionkey);

        Okhttp.get(API.Mulu + "?sessionkey=" + sessionkey, null, callback);

    }

    public static void CC(Context context
            , Okhttp.Objectcallback callback) {

        String sessionkey = (String) SpfUtils.get(context, "sessionkey", "");
        Log.e("CC", "URL" + API.CC + "&sessionkey=" + sessionkey);

        Okhttp.get(API.CC + "&sessionkey=" + sessionkey, null, callback);

    }

    public static void GR(Context context
            , Okhttp.Objectcallback callback) {

        String sessionkey = (String) SpfUtils.get(context, "sessionkey", "");
        Log.e("GeRen", "URL" + API.GeRen + "&sessionkey=" + sessionkey);

        Okhttp.get(API.GeRen + "&sessionkey=" + sessionkey, null, callback);

    }

    public static void Saveuserinfo(Context context, String names,
                                    String hometel,
                                    String mbnumber,
                                    String tel,
                                    String faddress,
                                    Okhttp.Objectcallback callback) {

        String sessionkey = (String) SpfUtils.get(context, "sessionkey", "");
        Log.e("GeRen", "URL" + API.Saveuserinfo + "&sessionkey=" + sessionkey);
        Map<String, String> map = new HashMap<>();
        //电话号码
        map.put("faddress", faddress);
        //身份证号
        map.put("mbnumber", mbnumber);
        map.put("tel", tel);
        map.put("hometel", hometel);
        map.put("names", names);
        Okhttp.get(API.Saveuserinfo + "&sessionkey=" + sessionkey, map, callback);

    }

    /**
     * 获取日志lieb
     * @param context
     * @param callback
     */
    public static void Getlist(Context context
            , Okhttp.Objectcallback callback) {

        String sessionkey = (String) SpfUtils.get(context, "sessionkey", "");
        Log.e("GeRen", "URL" + API.Getlist + "&sessionkey=" + sessionkey);

        Okhttp.get(API.Getlist + "&sessionkey=" + sessionkey, null, callback);

    }

    /**
     * 获取日志lieb
     * @param context
     * @param callback
     */
    public static void Getuser(Context context
            , Okhttp.Objectcallback callback) {

        String sessionkey = (String) SpfUtils.get(context, "sessionkey", "");
        Log.e("GeRen", "URL" + API.Getuser + "&sessionkey=" + sessionkey);

        Okhttp.get(API.Getuser + "&sessionkey=" + sessionkey, null, callback);

    }

    public static void AddFile(Context context,File file, String title,String sj,String info,String content,
            Okhttp.Objectcallback callback) {

        String sessionkey = (String) SpfUtils.get(context, "sessionkey", "");
        String sessionuid = (String) SpfUtils.get(context, "sessionuid", "");
        String sessionxid = (String) SpfUtils.get(context, "sessionxid", "");
        Log.e("GeRen", "URL" + API.getsp + "&sessionkey=" + sessionkey);
         Map<String, String> map = new HashMap<>();
        map.put("userid", sessionuid);
        map.put("xmid", sessionxid);
        map.put("title", title);
        map.put("sj", sj);
        map.put("info", info);
        map.put("content", content);
        String s = JSONUtils.mapToJson(map);
        Log.e("zzz", "xx"+s);


        Okhttp.addFile(API.getsp + "&sessionkey=" + sessionkey, map,file, callback);

    }



}



